gh-110819: Fix ‘kind’ may be used uninitialized warning in longobject#116599
Merged
Conversation
Contributor
|
@FFY00 has a similar PR up: |
Member
Author
longobjectlongobject
vstinner
reviewed
Mar 11, 2024
Contributor
|
This is a larger diff, but it avoids the initialisation: Detailsdiff --git a/Objects/longobject.c b/Objects/longobject.c
index 2d1c6ad788..a631dc05b2 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2197 +2196,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- int kind;
@@ -2249 +2247,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- kind = writer->kind;
@@ -2260 +2257,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- kind = PyUnicode_KIND(v);
@@ -2321,8 +2317,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- else if (kind == PyUnicode_1BYTE_KIND) {
- Py_UCS1 *p;
- WRITE_UNICODE_DIGITS(Py_UCS1);
- }
- else if (kind == PyUnicode_2BYTE_KIND) {
- Py_UCS2 *p;
- WRITE_UNICODE_DIGITS(Py_UCS2);
- }
@@ -2330,3 +2319,14 @@ long_format_binary(PyObject *aa, int base, int alternate,
- Py_UCS4 *p;
- assert (kind == PyUnicode_4BYTE_KIND);
- WRITE_UNICODE_DIGITS(Py_UCS4);
+ int kind = writer ? writer->kind : PyUnicode_KIND(v);
+ if (kind == PyUnicode_1BYTE_KIND) {
+ Py_UCS1 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS1);
+ }
+ else if (kind == PyUnicode_2BYTE_KIND) {
+ Py_UCS2 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS2);
+ }
+ else {
+ Py_UCS4 *p;
+ assert (kind == PyUnicode_4BYTE_KIND);
+ WRITE_UNICODE_DIGITS(Py_UCS4);
+ }
|
Member
I don't have much bandwidth right now, we can close mine in favor of this PR. |
Member
Author
|
@erlend-aasland yes, I liked your idea. I've implemented the change. Thank you! |
erlend-aasland
approved these changes
Mar 12, 2024
This comment was marked as outdated.
This comment was marked as outdated.
Member
Author
|
Thanks everyone involved 👍 |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Mar 12, 2024
…gobject` (pythonGH-116599) (cherry picked from commit eb947cd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This comment was marked as outdated.
This comment was marked as outdated.
|
GH-116648 is a backport of this pull request to the 3.12 branch. |
This comment was marked as outdated.
This comment was marked as outdated.
sobolevn
added a commit
to sobolevn/cpython
that referenced
this pull request
Mar 12, 2024
…in `longobject` (pythonGH-116599) (cherry picked from commit eb947cd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
|
GH-116650 is a backport of this pull request to the 3.11 branch. |
sobolevn
added a commit
to sobolevn/cpython
that referenced
this pull request
Mar 12, 2024
…in `longobject` (pythonGH-116599) (cherry picked from commit eb947cd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn
added a commit
that referenced
this pull request
Mar 12, 2024
sobolevn
added a commit
that referenced
this pull request
Mar 12, 2024
adorilson
pushed a commit
to adorilson/cpython
that referenced
this pull request
Mar 25, 2024
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this pull request
Apr 17, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've also added an
assertto make sure that both parameterswriterandbytes_writercannot be passed at the same time.longobject.c#116592maybe-uninitializedcompiler warnings onlong_format_binaryandlong_to_decimal_string_internal#110819